ISML Machine Learning, Class 15 Lab – Logistic Regression


This lab is about Logistic Regression. Follow the instructions below. Think hard before you call the instructors!

Download:


1. Linear Logistic Regression







2. Kernel Logistic Regression




figure

separatingKernLR(c, Xtr, kernel, sigma, Xts, Yts);

title({'Kernel Logistic Regression' ; 'Separating function and test samples' ; ['Sigma = ' , num2str(sigma) , ' Lambda = ' , num2str(lambda)] } );

xlabel('X') % x-axis label

ylabel('Y') % y-axis label

Yprob = Yts;

Yprob(Yprob==-1) = 0;

hold on

scatter(Xts(:,1), Xts(:,2), 25, Yprob,'filled');

hold off



c = kernLRTrain(Xtr, Ytr, kernel, sigma, lambda);

figure

confidenceLRKern(c, Xtr, kernel, sigma, Xts, Yts);

title({'Kernel Logistic Regression' ; 'Confidence function and test samples' ; ['Sigma = ' , num2str(sigma) , ' Lambda = ' , num2str(lambda)] } );

xlabel('X') % x-axis label

ylabel('Y') % y-axis label

Yprob = Yts;

Yprob(Yprob==-1) = 0;

hold on

scatter(Xts(:,1), Xts(:,2), 25, Yprob,'filled');

hold off







3. Parameter Selection


figure

semilogx(intLambda, Vm, 'b');

hold on

semilogx(intLambda, Tm, 'r');

xlabel('\lambda') % x-axis label

ylabel('Median error') % y-axis label

legend('Validation error','Training error');




4. If you have time - More experiments